hdu 5563 Clarke and five-pointed star 水题

Clarke and five-pointed star

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5563

Description

Clarke is a patient with multiple personality disorder. One day, Clarke turned into a learner of geometric.
When he did a research with polygons, he found he has to judge if the polygon is a five-pointed star at many times. There are 5 points on a plane, he wants to know if a five-pointed star existed with 5 points given.

 

Input

The first line contains an integer T(1≤T≤10), the number of the test cases.
For each test case, 5 lines follow. Each line contains 2 real numbers xi,yi(−109≤xi,yi≤109), denoting the coordinate of this point.

Output

Two numbers are equal if and only if the difference between them is less than 10−4.
For each test case, print Yes if they can compose a five-pointed star. Otherwise, print No. (If 5 points are the same, print Yes. )

Sample Input

2
3.0000000 0.0000000
0.9270509 2.8531695
0.9270509 -2.8531695
-2.4270509 1.7633557
-2.4270509 -1.7633557
3.0000000 1.0000000
0.9270509 2.8531695
0.9270509 -2.8531695
-2.4270509 1.7633557
-2.4270509 -1.7633557

Sample Output

Yes
No

HINT

 

题意

给你五个点,问你是否能够构成一个正五边形,精度要求1e-4

题解:

直接判断是否有五条边相同,是否有五条对角线长度相同就好了

代码

#include<iostream>
#include<stdio.h>
#include<map>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
const double eps = 1e-6;
struct node
{
    double x,y;
};
node p[12];
vector<double> Q;
double dis(node a,node b)
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int is_equal(double x,double y)
{
    return fabs(x-y)<eps;
}
map<long long,int> H;
int main()
{
    int t;scanf("%d",&t);
    for(int cas=1;cas<=t;cas++)
    {
        H.clear();
        Q.clear();
        for(int i=0;i<5;i++)
            scanf("%lf%lf",&p[i].x,&p[i].y);
        for(int i=0;i<5;i++)
        {
            for(int j=i+1;j<5;j++)
            {
                Q.push_back(dis(p[i],p[j]));
            }
        }
        int flag = 0;
        sort(Q.begin(),Q.end());
        for(int i=0;i<Q.size();i++)
        {
            long long p = (100000.0*Q[i])*1LL;
            if(H[p]==0)
            {
                H[p]++;
                flag++;
            }
            else
                H[p]++;
        }
        if(flag>2)
        {
            printf("No\n");
            continue;
        }
        long long p1 = 1LL*(100000.0*Q[0]);
        long long p2 = 1LL*(100000.0*Q[9]);
        if(H[p1]==10)
        {
            printf("Yes\n");
            continue;
        }
        if(H[p1]!=5&&H[p2]!=5)
        {
            printf("No\n");
            continue;
        }
        printf("Yes\n");
    }
}

 

posted @ 2015-11-14 23:05  qscqesze  阅读(281)  评论(0编辑  收藏  举报